home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / sectools / SRS / server / src / stream.c < prev   
Encoding:
C/C++ Source or Header  |  2000-01-12  |  4.1 KB  |  156 lines

  1. #include "headers.h" /* has all important stuff */
  2.  
  3. /* this file does the authentication stuff */
  4.  
  5. /* read data from SYSLOGFILE.. and send it to server */
  6. void readStream()
  7. {
  8.    int count = 0;         /* prevent overflows */
  9.  
  10.    char newmsg[MAXLOGSIZE];
  11.    char logmsg[MAXLOGSIZE];
  12.    char rawmsg[MAXLOGSIZE];
  13.  
  14.    char readbuf[MAXREADSIZE];
  15.    char *dataptr, *logptr, *newptr, *rawptr;  
  16.  
  17.    debug("(in readStream) waiting for client's logs..\n\n");
  18.  
  19.  
  20.    while(1)
  21.    {
  22.       logptr = logmsg, rawptr = rawmsg, newptr = newmsg;
  23.  
  24.       memset(logmsg,  0, sizeof(logmsg));
  25.       memset(newmsg,  0, sizeof(newmsg));
  26.       memset(rawmsg,  0, sizeof(rawmsg));
  27.  
  28.       while(1)
  29.       {
  30.          memset(readbuf, 0, sizeof(readbuf));
  31.  
  32.          recv_data((clients[curClient]).sockfd, readbuf, 
  33.                    sizeof(readbuf)-1, (child == 1 ? 1 : 0));
  34.  
  35.          if (debugging == 1)
  36.          {
  37.             (void)putchar('\n');
  38.             (void)write(dblogfd, "\n", 1);
  39.          }
  40.  
  41.          if (strlen(readbuf) <= 17)
  42.             debug("(in readStream).. the data is: %s%c", readbuf,
  43.                   (strchr(readbuf, '\n') == NULL ? '\n' : '\0'));
  44.  
  45.          else
  46.             debug("(in readStream).. the data is:\n%s%c", readbuf,
  47.                   (strchr(readbuf, '\n') == NULL ? '\n' : '\0'));
  48.  
  49.          /* check for the possible cmds we could get in this state */
  50.          if (strncmp(readbuf, "END STREAM", 10) == 0) 
  51.          {
  52.             error("got request to stop streaming from client\n\n");
  53.             return;
  54.          }
  55.  
  56.          else if (strncmp(readbuf, "STREAM : ", 9) == 0) break;
  57.          else if (strncmp(readbuf, "START SYSLOG.CONF", 17) == 0)
  58.                  readSysConf(); 
  59.  
  60.          else if (strncmp(readbuf, "START PINGS", 10) == 0) startPings();
  61.          else if (strncmp(readbuf, "PONG", 4) == 0) continue;
  62.          else if (strncmp(readbuf, "PING CHECK", 10) == 0) continue;
  63.          else
  64.          {
  65.             error("unknown message from client:\n%s\n%c", readbuf,
  66.                   (strchr(readbuf, '\n') == NULL ? '\n' : '\0'));
  67.  
  68.             continue;
  69.          }
  70.       }
  71.  
  72.       /* parse it to get time value.. */
  73.       dataptr = strstr(readbuf, "STREAM :");
  74.       dataptr += 9; /* skip the "STREAM : " */
  75.  
  76.       count = 0;
  77.       while ((*dataptr) && (isprint(*dataptr) != 0) && 
  78.             (count < (int)sizeof(logmsg)))
  79.       {
  80.          *logptr++ = *dataptr++;
  81.          count++;
  82.       }
  83.  
  84.       /* -------------------------------- */
  85.  
  86.       count = 0;
  87.       dataptr = logmsg, dataptr += 20;
  88.  
  89.       while((*dataptr) && (isprint(*dataptr) != 0) &&
  90.             (count < (int)sizeof(rawmsg)))
  91.       {
  92.          *rawptr++ = *dataptr++;
  93.          count++;
  94.       }
  95.  
  96.       if (isprint(prevlogmsg[0]) == 0)
  97.       {
  98.          memset(prevlogmsg, 0, sizeof(prevlogmsg));
  99.          (void)strncpy(prevlogmsg, rawmsg, sizeof(prevlogmsg)-1);
  100.  
  101.          prevlogtime = time(NULL);
  102.  
  103.          doLogging(logmsg);         
  104.       }
  105.  
  106.       else if (strncmp(rawmsg, prevlogmsg, strlen(prevlogmsg)) == 0)
  107.       {
  108.          if ((time(NULL) - prevlogtime) >= REPTIME)
  109.          {
  110.             char repmsg[MAXLOGSIZE - 20];
  111.  
  112.             memset(repmsg, 0, sizeof(repmsg));
  113.  
  114.             if (repcount == 1)
  115.                sprintf(repmsg, " last message repeated %d time\n", repcount);
  116.  
  117.             else
  118.                sprintf(repmsg, " last message repeated %d times\n", repcount);
  119.  
  120.             repcount = 0;
  121.             prevlogtime = time(NULL);
  122.  
  123.             count = 0;
  124.             newptr = newmsg, dataptr = logmsg;
  125.  
  126.             while((*dataptr) && (isprint(*dataptr) != 0) &&
  127.                   (count < (int)sizeof(newmsg)) && (count < 19))
  128.             {
  129.                *newptr++ = *dataptr++;
  130.                count++;
  131.             }
  132.  
  133.             strncat(newmsg, repmsg, sizeof(newmsg) - strlen(newmsg) - 1);
  134.  
  135.             debug("newmsg = %s\n", newmsg); 
  136.             doLogging(newmsg);
  137.          }
  138.  
  139.          else
  140.          {
  141.             debug("last message repeated..\n\n");
  142.             repcount++;
  143.          }
  144.       }
  145.  
  146.       else
  147.       {
  148.          prevlogtime = time(NULL);
  149.          strncpy(prevlogmsg, rawmsg, sizeof(prevlogmsg)-1);
  150.          doLogging(logmsg);           /* parse system log message */
  151.       }
  152.    }
  153.  
  154.    return;
  155. }
  156.